package com.dartfar.util;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Set;

public class ListUtil<T> {
	public List<T> removeRepeat(Set<T> setT,List<T> listT){
		//遍历用户角色的模块
		for(Iterator<T> i = setT.iterator();i.hasNext();){
			//是否重复
			boolean isRepeat = false;
			T t = i.next();
			//遍历显示权限中的模块
			for(Iterator<T> j = listT.iterator();j.hasNext();){
				T t1 = j.next();
				//如果用户权限已在显示权限中
				if(t.equals(t1)){
					isRepeat = true;
				}
			}
			
			//如果不重复
			if(!isRepeat){
				listT.add(t);
			}
		}
		
		return listT;
	}
	
	public List<T> removeRepeat(List<T> setT,List<T> listT){
		//遍历用户角色的模块
		for(Iterator<T> i = setT.iterator();i.hasNext();){
			//是否重复
			boolean isRepeat = false;
			T t = i.next();
			//遍历显示权限中的模块
			for(Iterator<T> j = listT.iterator();j.hasNext();){
				T t1 = j.next();
				//如果用户权限已在显示权限中
				if(t.equals(t1)){
					isRepeat = true;
				}
			}
			
			//如果不重复
			if(!isRepeat){
				listT.add(t);
			}
		}
		
		return listT;
	}
	
	public List<T> removeRepeat(List<T> listT){
		List<T> newList = new ArrayList<T>();
		for(Iterator<T> i = listT.iterator();i.hasNext();){
			boolean isRepeat = false;
			T t = i.next();
			for(Iterator<T> j = newList.iterator();j.hasNext();){
				T t1 = j.next();
				if(t.equals(t1)){
					isRepeat = true;
				}
			}
			
			if(!isRepeat){
				newList.add(t);
			}
		}
		
		return newList;
	}
}
